package com.xnyzc.lhy.order.service.impl.jpush;

import com.alibaba.fastjson.JSONObject;
import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.util.TokenUtil;
import com.xnyzc.lhy.order.feign.push.FeignMessageSendService;
import com.xnyzc.lhy.order.service.jpush.OajPushService;
import com.xnyzc.lhy.resource.entity.jpush.BizResult;
import com.xnyzc.lhy.resource.entity.jpush.PushInfoEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 极光推送 服务实现类
 * </p>
 *
 * @author liuju
 * @since 2019-09-20
 */
@Slf4j
@Service
public class OajPushServiceImpl implements OajPushService {

    @Autowired
    private FeignMessageSendService feignMessageSendService;

    /**
     * 极光推送调用示例
     * @return
     */
    @Override
    public Rv sendJPushMessage() {

        List<String> aliasList = new ArrayList<>();
        aliasList.add("Passenger15201047430");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("orderNo", "123456");
        jsonObject.put("sound", "sound1");
        jsonObject.put("jumpKey", "0");

        PushInfoEntity pushInfoEntity = new PushInfoEntity();
        pushInfoEntity.setPushCode("test");
        pushInfoEntity.setPhones(aliasList);
        pushInfoEntity.setExtras(jsonObject);
        pushInfoEntity.setClientId(TokenUtil.getClientId());
        pushInfoEntity.setTag(TokenUtil.getTag());
        BizResult bizResult = feignMessageSendService.pushMessage(pushInfoEntity);

        log.info("{}", bizResult.toString());

        if (bizResult.getCode() == 1) {
            log.info("推送成功");
        } else {
            log.info("推送失败");
        }

        return null;
    }
}
